package com.midea.leetcode;

import javax.swing.tree.TreeNode;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @description：BFS和DFS两种方法求二叉树的最短路径
 * @author: wangwl23
 * @create: 2021-03-25 14:15
 */
public class LeetCode111 {
    public static void main(String[] args) {

    }
    public int bfs(TreeNode root) {
        if (root ==null){
            return 0;
        }
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        int depth = 1;
        while (!q.isEmpty()){
            int sz = q.size();
            for (int i = 0;i<sz;i++){
                TreeNode poll = q.poll();
               /* if(poll.left != null && poll .right != null){
                    return depth;
                }
                if (poll.left != null){
                    q.offer(pool.left);
                }
                if (poll.right != null){
                    q.offer(poll.right)
                }*/
            }
            depth++;
        }
        return depth;
    }

    /*public int dfs(TreeNode root) {
        if(root==null){
            return 0;
        }
        if(root.left ==null && root.right ==null){
            return 1;
        }
        int min = Integer.MAX_VALUE;
        if(root.left != null){
            min = Math.min(dfs(root.left,min));
        }
        if(root.right != null){
            min = Math.min(dfs(root.right,min));
        }
        return min+1;
    }*/
}
